import 'package:getx_mvvm_lite/core/base/list_view_model.dart';
import 'package:getx_mvvm_lite/core/state/result.dart';
import 'package:get/get.dart';
import 'package:getx_mvvm_lite/features/todo/todo_model.dart';
import 'package:getx_mvvm_lite/features/todo/todo_repository.dart';

class TodoViewModel extends ListViewModel<Todo> {
  final TodoRepository repo = Get.find<TodoRepository>();

  TodoViewModel() : super((page, pageSize) async {
    final Result<List<Todo>> res = await Get.find<TodoRepository>()
        .fetchTodos(page: page, pageSize: pageSize);
    if (res.isOk) {
      return res.data ?? [];
    } else {
      throw Exception(res.error);
    }
  });
}